package ua.lviv.franko.solvers.oneDimention;

import ua.lviv.franko.matrix.hash.lu.HashMatrixLUStyle;

public class BoundaryConditions {
	private boolean	dirihletLeft;
	private double	parameterLeft;
	private boolean	dirihletRight;
	private double	parameterRight;

	public BoundaryConditions(boolean isDirihletLeft, double valL, boolean isDirihletRight, double valR) {
		this.dirihletLeft = isDirihletLeft;
		this.dirihletRight = isDirihletRight;
		this.parameterLeft = valL;
		this.parameterRight = valR;
	}

	public void Apply(HashMatrixLUStyle A, double[] b) {
		if (dirihletLeft) {
			A.getJRowIndex(0).clear();
			A.getJRowValues(0).clear();
			A.setValue(0, 0, 1);
			b[0] = this.parameterLeft;
		} else {
			b[0] += parameterLeft;
		}
		if (dirihletRight) {
			A.getJRowIndex(A.getN() - 1).clear();
			A.getJRowValues(A.getN() - 1).clear();
			A.setValue(A.getN() - 1, A.getN() - 1, 1);
			b[b.length - 1] = this.parameterRight;
		} else {
			b[b.length - 1] += parameterRight;
		}
	}

}
